const http = require("http");
const ejs = require("ejs");
let app = require("./module/route.js");
http
  .createServer(app) //一请求服务器就会触发app方法
  .listen(3000, function () {
    console.log("The server is running at http://localhost:3000");
  });

//配置静态web目录
app.static("public");
//模拟express配置路由
app.get("/login", function (req, res) {
  res.writeHead(200, { "Content-Type": 'text/html;charset="utf-8"' });
  ejs.renderFile("./views/login.ejs", function (error, data) {
    if (error) {
      console.log(data);
      return;
    }
    res.send(data);
  });
});
app.get("/news", function (req, res) {
  res.send("news");
});
app.post("/doLogin", function (req, res) {
  res.send(req.body);
});
